<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <home></home>
  </div>
  <script src="./vue.js"></script>
  <script>
    const Child = {
      template: `
        <div>
            <h3>这是子组件</h3>  
            <button @click="biubiubiu">点击向父组件通信</button>
        </div>
      `,
       data(){
         return {
           msg: '这是子组件中的数据'
         }
       },
       methods: {
        biubiubiu(){
          // 触发 Vue实例的自定义事件
          this.$emit('piupiu', this.msg);
        }
       }
    }
    const Home = {
      template: `
        <div>
          <h2>这是父组件</h2>  
          {{ msg }}
          <hr/>
          <child @piupiu="fn"></child>
        </div>
      `,
      data(){
        return {
          msg: ''
        }
      },
      methods: {
        fn(msg){
          console.log('子组件传递的数据到了是', msg);
          this.msg = msg;
        }
      },
      components: {
        Child
      }
    }

    Vue.component('Home', Home)
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>